package miaofusdk

import (
	"encoding/json"
)

type UnionDbqBean struct {
	TradeNo                  string `json:"trade_no,omitempty"`
	UpTradeNo                string `json:"up_trade_no,omitempty"`
	DownTradeNo              string `json:"down_trade_no,omitempty"`
	BuyerId                  string `json:"buyer_id,omitempty"`
	TradeStatus              string `json:"trade_status,omitempty"`
	TimeEnd                  string `json:"time_end,omitempty"`
	TradeDate                string `json:"trade_date,omitempty"`
	TradeTime                string `json:"trade_time,omitempty"`
	BatchNo                  int    `json:"batch_no,omitempty,string"`
	UndiscountableAmt        string `json:"un_discountable_amt,omitempty"`
	OperId                   string `json:"oper_id,omitempty"`
	TradeType                string `json:"trade_type,omitempty"`
	Subject                  string `json:"subject,omitempty"`
	GoodsDetail              string `json:"goods_detail,omitempty"`
	RawData                  string `json:"rawdata,omitempty"`
	OrgCode                  string `json:"org_code,omitempty"`
	ShopCode                 string `json:"shop_code,omitempty"`
	StoreCode                string `json:"store_code,omitempty"`
	TerminalCode             string `json:"terminal_code,omitempty"`
	StoreName                string `json:"store_name,omitempty"`
	TotalAmount              string `json:"total_amount,omitempty"`
	Fee                      string `json:"fee,omitempty"`
	RefundTime               string `json:"refund_time,omitempty"`
	PayCardType              string `json:"pay_card_type,omitempty"`
	UnionIcRemark            string `json:"union_ic_remark,omitempty"`
	UnionCardExpiry          string `json:"union_card_expiry,omitempty"`
	TerminalId               string `json:"terminal_id,omitempty"`
	UnionTerminalId          string `json:"union_terminal_id,omitempty"`
	UnionSerialNo            string `json:"union_serial_no,omitempty"`
	UnionAcquiringBand       string `json:"union_acquiring_band,omitempty"`
	UnionBankCardAssociation string `json:"union_bank_card_association,omitempty"`
	UnionIssuingBank         string `json:"union_issuing_bank,omitempty"`
	UnionRefNo               string `json:"union_ref_no,omitempty"`
	UnionStoreName           string `json:"union_store_name,omitempty"`
	UnionMchCode             string `json:"union_mch_code,omitempty"`
	UnionBatchNo             string `json:"union_batch_no,omitempty"`
	UnionSelectId            string `json:"union_select_id,omitempty"`
	UnionAuthCode            string `json:"union_auth_code,omitempty"`
	TransactionType          string `json:"transaction_type"`
	Longitude                string `json:"longitude,omitempty"`
	Latitude                 string `json:"latitude,omitempty"`
	MobileNo                 string `json:"mobile_no,omitempty"`
	StateCode                string `json:"state_code,omitempty"`
	ServerCode               string `json:"server_code,omitempty"`
	TicketUrl                string `json:"ticket_url,omitempty"`
	RefundTicketUrl          string `json:"refund_ticket_url,omitempty"`
	Remark                   string `json:"remark,omitempty"`
	FromMobileNo             string `json:"from_mobile_no,omitempty"`
	SellerAmount             int    `json:"seller_amount,string"`
	SellerCoupon             int    `json:"seller_coupon,string"`
	BuyerAmount              int    `json:"buyer_amount,string"`
	ChnCoupon                int    `json:"chn_coupon,string"`
	ErrMsg                   string `json:"err_msg,omitempty"`
	TradeChannel             string `json:"trade_channel"`
	UnionCardNo              string `json:"union_card_no"`
}

type RespUnionDbq struct {
	Response
	Data UnionDbqBean `json:"data,omitempty"`
}

type RespUnionDbqs struct {
	Response
	Page       int            `json:"page,string"`
	Rows       int            `json:"rows,string"`
	TotalCount int            `json:"total_count,string"`
	TotalPage  int            `json:"total_page,string"`
	List       []UnionDbqBean `json:"list,omitempty,string"`
}

func (s *SrvUnionDbqManager) OrderQuery(trade_no, up_trade_no, store_code string) (RespUnionDbq, error) {
	resp := RespUnionDbq{}
	http_request := s.GetPost(s.GetUrl() + "/dbq/queryorder/" + store_code)
	http_request.Param("trade_no", trade_no)
	http_request.Param("up_trade_no", up_trade_no)
	if v, err := http_request.Bytes(); err != nil {
		return resp, err
	} else if err := json.Unmarshal(v, &resp); err != nil {
		return resp, err
	} else {
		return resp, nil
	}
}
